<template>
	<view>
		<comlist 
			title="创建健康风险评估汇总" 
			:listtitle="listtitle" 
			:listLabel="listLabel" 
			:list="list" 
			:options="options" 
			:addpageUrl="'/pages/quickly/summary/createSummary'" 
			@bindClick="bindClick" 
			@jump="jump"
			@comSearch="comSearch" 
			:nullData="nullData"
		>
		</comlist>
		<u-modal v-model="showModal" :show-cancel-button="true" @confirm="Modalconfirm" :content="showContent"></u-modal>
	</view>
</template>

<script>
import comlist from '@/components/comlist/index.vue'	
import {filterData2} from '@/static/js/filter.js'
export default{
	components:{comlist},
	data() {
		return {
			list: null,
			options: [{
				text: '删除',
				style: {
					backgroundColor: '#EE2437' ,// 删除按钮背景  红的
				}
			}],
			listtitle:'健康风险评估汇总',
			listLabel:[
				{
					name:'评估编号：',
					key:'sn'
				},
				{
					name:'签发时间：',
					key:'modifiedDate'
				},
			],
			showModal:false,
			showContent:'',
			nullData:false,
			SearchuserId:'',
			page:1
		}
	},
	onLoad() {
		this.getlist({pageSize:10,pageIndex:1})
	},
	methods:{
		onReachBottom(){
			if(this.nullData == true){
				return;
			}
			this.page = this.page + 1
			this.getlist({pageSize:10,pageIndex:this.page,userId:this.SearchuserId})
		},
		comSearch(e) {
			this.page = 1
			this.SearchuserId = e == 'all'? '' : e.userId
			this.nullData = false
			this.deleteList = 1
			this.getlist({pageSize:10,pageIndex:1,userId:e.userId})
		},
		filterData2,
		getlist(data){
			const _this = this;
			_this.$api.HealthRiskslist(data).then(res=>{
				const data = res.data.result && res.data.result.elements
				if(_this.deleteList == 1) {
					_this.list = []
					_this.list = data
					_this.deleteList = ''
				}else {
					_this.list = _this.list ? _this.list.concat(data) : data
				}
				if(this.list.length >= res.data.result.totalCount){
					this.nullData = true;
				}
			})
		},
		bindClick(e){
			this.showModal = true
			this.showContent = '是否删除此汇总'
			this.delItem = e
		},
		Modalconfirm(){
			this.$api.HealthRisksdel(this.delItem.id).then((res)=>{
				if(res.data.returnCode == 200){
					uni.showToast({
						title:'删除成功',
						icon:'none'
					})
					setTimeout(() => {
						this.nullData = false
						this.page = 1
						this.deleteList = 1
						this.getlist({pageSize:10,pageIndex:1,userId:this.SearchuserId})
					},500)
				}
			})
		},
		jump(item){
			!item.status || item.status == 1?
				uni.navigateTo({url:'/pages/quickly/summary/createSummary?id='+item.id+'&userId='+item.userId+'&userName='+item.userName})
			:
				uni.navigateTo({url:'/pages/quickly/summary/toView?id='+item.id+'&userId='+item.userId+'&userName='+item.userName})
		}
	}
}
</script>

<style>
	
</style>
